﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RedBlueBalls
{
    class RedPrime
    {
        private static bool analyzed = false;
        private static bool checkBest = false;
        private static int lastPrimes = 0;

        public static void analyze(RedBlueBallRecord[] records)
        {
            if (checkBest)
            {
                int[] primes = new int[7];
                for (int i = 0; i < 7; i++)
                    primes[i] = 0;

                foreach (RedBlueBallRecord record in records)
                {
                    primes[record.GetPrimes()]++;
                }

                for (int i = 0; i < 7; i++)
                    Tracer.AppendMessage(String.Format("Primes {0}: {1}", i, primes[i]));
            }

            lastPrimes = records[records.Length - 1].GetPrimes();

            analyzed = true;
        }

        public static bool predict(RedBlueBallRecord candidate)
        {
            if (!analyzed)
            {
                Tracer.AppendMessage("Please analyze the data first!");
                return false;
            }

            int primes = candidate.GetPrimes();

            // Ignore 20% rare data
            if (primes == 0 || primes > 4)
                return false;

            // Ingore the same primes as the last one
            if (primes == lastPrimes)
                return false;

            return true;
        }
    }
}
